﻿#region Usings
using System.Linq;

using BK.Model;
using BK.Repositories.Abstract;
#endregion

namespace BK.Repositories.EF
{
    public class FinancistoFilesRepository : BaseRepository<FinancistoFile, ImportedFile, BkDataContext>, IFinancistoFilesRepository
    {
        #region C'tors
        public FinancistoFilesRepository(BkDataContext dataContext) : base(dataContext)
        {
        }
        #endregion

        public ImportedFile GetAnotherByExpense(FinancistoExpense expense)
        {
            FinancistoExpensesRepository financistoExpensesRepository = new FinancistoExpensesRepository(Context);

            FinancistoFile result = (from fe in financistoExpensesRepository.ObjectSet
                                       where fe.Date == expense.Date &&
                                             fe.Amount == expense.Amount &&
                                             fe.Currency == expense.Currency &&
                                             fe.Category == expense.Category &&
                                             fe.Note == expense.Note &&
                                             fe.Account == expense.Account &&
                                             fe.FinancistoFile.Id != expense.FinancistoFile.Id
                                       select fe.FinancistoFile).FirstOrDefault();

            return result;
        }
    }
}